angular.module('inspinia').controller('agentRewardRecordQueryCtrl',function($scope,$http,i18nService,SweetAlert,$document){
    i18nService.setCurrentLang('zh-cn');  //设置语言为中文
    $scope.paginationOptions=angular.copy($scope.paginationOptions);

    $scope.actTypeSelect = [{text:"全部",value:""},{text:"百团大战",value:"1"},{text:"千团大战",value:"2"}];
    $scope.actTypeStr=angular.toJson($scope.actTypeSelect);

    //清空
    $scope.clear=function(){
        $scope.info={actType:"",actName:"",agentNo:""};
    };
    $scope.clear();

    $scope.userGrid={                           //配置表格
        data: 'result',
        paginationPageSize:10,                  //分页数量
        paginationPageSizes: [10,20,50,100],	//切换每页记录数
        useExternalPagination: true,		    //开启拓展名
        enableHorizontalScrollbar: true,        //横向滚动条
        enableVerticalScrollbar : true,  		//纵向滚动条
        columnDefs:[                           //表格数据
            { field: 'actCode',displayName:'活动编号',width:180},
            { field: 'actName',displayName:'活动名称',width:180},
            { field: 'actType',displayName:'子活动名称',width:180,cellFilter:"formatDropping:" +  $scope.actTypeStr },
            { field: 'rankSeq',displayName:'排名',width:180},
            { field: 'rewardName',displayName:'奖项',width:180 },
            { field: 'agentNo',displayName:'代理商编号',width:180 },
            { field: 'agentName',displayName:'代理商名称',width:180 },
            { field: 'mobilephone',displayName:'手机号码',width:180 },
            { field: 'oneAgentNo',displayName:'一级代理商编号',width:180 },
            { field: 'oneAgentName',displayName:'一级代理商名称',width:180 },
            { field: 'oneSaleName',displayName:'一级代理商所属销售',width:180 },
            { field: 'createTime',displayName:'领取时间',cellFilter: 'date:"yyyy-MM-dd HH:mm:ss"',width:180}
        ],
        onRegisterApi: function(gridApi) {
            $scope.gridApi = gridApi;
            gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
                $scope.paginationOptions.pageNo = newPage;
                $scope.paginationOptions.pageSize = pageSize;
                $scope.query();
            });
        }
    };
    $scope.query=function(){
        if ($scope.loadImg) {
            return;
        }
        $scope.loadImg = true;
        var data = {
            info:angular.toJson($scope.info),
            pageNo:$scope.paginationOptions.pageNo,
            pageSize:$scope.paginationOptions.pageSize
        };
        $http.post("agentRewardRecordAction/selectAll",data,$scope.postCfgAllCurrency)
            .success(function (data) {
                if (data.status) {
                    $scope.result=data.page.result;
                    $scope.userGrid.totalItems = data.page.totalCount;
                } else {
                    $scope.notice(data.msg);
                }
                $scope.loadImg = false;
            }).error(function(data){
                 $scope.notice(data.msg);
                 $scope.loadImg = false;
            });
    };

    //导出
    $scope.exportExcel=function(){
        SweetAlert.swal({
                title: "确认导出？",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "提交",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true },
            function (isConfirm) {
                if (isConfirm) {
                    $scope.exportInfoClick("agentRewardRecordAction/exportExcel",{"info" : angular.toJson($scope.info)});
                }
            });
    };

    //页面绑定回车事件
    $document.bind("keypress", function(event) {
        $scope.$apply(function (){
            if(event.keyCode == 13){
                $scope.query();
            }
        })
    });
});